package com.example.app.ui.chat;

import androidx.lifecycle.ViewModel;
import androidx.lifecycle.MutableLiveData;
import com.example.app.model.ChatMessage;
import java.util.ArrayList;
import java.util.List;

public class ChatViewModel extends ViewModel {
    private final MutableLiveData<List<ChatMessage>> messages = new MutableLiveData<>(new ArrayList<>());
    
    public MutableLiveData<List<ChatMessage>> getMessagesLiveData() {
        return messages;
    }
    
    public List<ChatMessage> getMessages() {
        List<ChatMessage> currentMessages = messages.getValue();
        if (currentMessages == null) {
            currentMessages = new ArrayList<>();
            messages.setValue(currentMessages);
        }
        return currentMessages;
    }
    
    public void addMessage(ChatMessage message) {
        List<ChatMessage> currentMessages = getMessages();
        currentMessages.add(message);
        messages.setValue(currentMessages);
    }
    
    public void clearMessages() {
        messages.setValue(new ArrayList<>());
    }
} 